package com.ztgf.logistics.service.async;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.ztgf.logistics.models.bo.deppon.LogisticsHttpLogSaveBO;
import com.ztgf.logistics.models.dto.deppon.LogisticsBillPlatDTO;
import com.ztgf.logistics.models.service.deppon.IAsyncLogisticsOrderService;
import com.ztgf.logistics.models.service.deppon.ILogisticsBillPlatService;
import com.ztgf.logistics.models.service.deppon.ILogisticsHttpLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.scheduling.annotation.Async;

import javax.annotation.Resource;

/**
 * @Description:
 * @Author: mxli
 * @Date: 2021-12-09 18:42
 **/
@DubboService
@Slf4j
public class AsyncLogisticsOrderServiceImpl implements IAsyncLogisticsOrderService {

    @Resource
    private ILogisticsHttpLogService logisticsHttpLogService;
    @Resource
    private ILogisticsBillPlatService logisticsBillPlatService;

    @Override
    @Async
    public void addDepponHttpLog(LogisticsHttpLogSaveBO saveBO) {
        logisticsHttpLogService.add(saveBO);
    }

    @Override
    @Async
    public void saveSure(Long id) {
        int status = 3;
        try {
            status = 2;
            logisticsBillPlatService.saveSure(id);
        } catch (Exception e){
            log.error("确定账单错误", e);
        }

        LogisticsBillPlatDTO dto = new LogisticsBillPlatDTO();
        dto.setId(id);
        dto.setSureStatus(status);
        Wrapper wrapper = new EntityWrapper();
        wrapper.eq("id", id);
        wrapper.eq("sure_status", 1);
        boolean flag = logisticsBillPlatService.update(dto, wrapper);
        if(!flag){
            log.error("修改订单确定状态错误"+id);
        }
    }


}
